package uk.me.dewi.appenin.android.dao.rest;

import org.apache.http.HttpRequest;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpOptions;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpTrace;

public abstract class AppeninHttpRequestFactory {
    
    private String baseUrl;
    
    public AppeninHttpRequestFactory(){
    }
    
    public AppeninHttpRequestFactory(String baseUrl){
        this();
        this.baseUrl = baseUrl;
    }

    public HttpPost newHttpPost(String uri){
        return (HttpPost) configureRequest(new HttpPost(baseUrl+uri));
    }

    public HttpPut newHttpPut(String uri){
        return (HttpPut) configureRequest(new HttpPut(baseUrl+uri));
    }

    public HttpGet newHttpGet(String uri){
        return (HttpGet) configureRequest(new HttpGet(baseUrl+uri));
    }

    public HttpHead newHttpHead(String uri){
        return (HttpHead) configureRequest(new HttpHead(baseUrl+uri));
    }

    public HttpDelete newHttpDelete(String uri){
        return (HttpDelete) configureRequest(new HttpDelete(baseUrl+uri));
    }

    public HttpOptions newHttpOptions(String uri){
        return (HttpOptions) configureRequest(new HttpOptions(baseUrl+uri));
    }

    public HttpTrace newHttpTrace(String uri){
        return (HttpTrace) configureRequest(new HttpTrace(baseUrl+uri));
    }

    protected abstract HttpRequest configureRequest(HttpRequest request);

    public String getBaseUrl() {
        return baseUrl;
    }

    public void setBaseUrl(String baseUrl) {
        this.baseUrl = baseUrl;
    }
}
